<?php
namespace App\Common\Lib\Fun\Array_;

use App\Common as com;
use App\Common\Lib\Fun\Array_\ArrayPool as thisArrayPool;

class ArrayPool extends com\Lib\LibBase {

	/**
	 * 池尺寸
	 * @var int
	 */
	private int $poolSize;

	private array $arrays = [];

	public function __construct( int $poolSize ) {
		$this->poolSize = $poolSize;
		//
		parent::__construct();
	}

	public function getPoolSize(  ):int {
		return $this->poolSize;
	}

	public function push( $value ) {
		// 开头插入
		array_unshift( $this->arrays, $value );
		// 删除多余数据
		if( count( $this->arrays ) > $this->getPoolSize() ){
			array_pop( $this->arrays );
		}
		//
		return $this;
	}

	public function getArrays(  ):array {
		return $this->arrays;
	}
	// ===============================
	//
	//
	// 下面为静态方法
	//
	//
	// ===============================

	/**
	 * @param int $poolSize
	 * @return $this
	 */
	public static function makeOfNew( int $poolSize ):self {
		return self::make( $poolSize );
	}

}
